module AList (AList,
              nil,
              get,
              put,
              del,
              isNil,
              isIn) where

type AList a = [(Char, a)]

nil :: AList a
nil = []

isNil :: AList a -> Bool
isNil [] = True
isNil _  = False

put :: Char -> a -> AList a -> AList a
put k v [] = [(k, v)]
put k v ((k1, v1) : ps) = if k == k1
                          then (k, v):ps
                          else (k1, v1):put k v ps

isIn :: Char -> AList a -> Bool
isIn k []             = False
isIn k ((k1, _) : ps) = if k == k1
                        then True
                        else isIn k ps

get :: Char -> AList a -> Maybe a
get k []            = Nothing
get k ((k1, v1):ps) = if k == k1
                      then Just v1
                      else get k ps

del :: Char -> AList a -> AList a
del _ []            = []
del k ((k1, v1):ps) = if k == k1
                      then ps
                      else (k1, v1):del k ps
